/**
 * <b> 文件: </b> Search.java
 * @author xhe
 * @version V1.0.0.0
 * @version --2020-10-27
 */
package xhe.lib.data;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.sql.rowset.CachedRowSet;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;
import xhe.entities.ApiEntity;
import xhe.entities.RSEntity;
import xhe.enums.ExecuteEnum;
import xhe.lib.base.Common;
import xhe.lib.date.DateTime;
import xhe.lib.db.BaseFactory;

/**
 * <b> 类: </b> Search.java
 * 
 * @author xhe
 * @version V1.0.0.0
 * @version --2020-10-27
 */
public class Get {
	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2020年5月6日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity Get_1_0(ApiEntity requestEntity) {

		CachedRowSet rs = null;
		ResultSet rsEx = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取表名
			String strTable = jsonObject.getString("Table");

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			String strColumns = Util.getColumns(strParams);
			Map<String, List<String>> strColumnList = Util.getColumnList(strParams);

			// System.out.println("Columns:" + strColumns);

			// 查询条件
			String strFilter = Util.getFilter(strParams);

			// System.out.println("Filter:" + strFilter);

			// 页面大小
			int iRows = Common.toPraseInt(jsonObject.getString("Rows"), 0);
			// 页码
			int iPage = Common.toPraseInt(jsonObject.getString("Page"), 0);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 页面大小
			String strSortOrder = jsonObject.getString("SortOrder");
			// 总条数
			int iTotal = 0;

			// 查询语句
			String strSql = "";

			if (iRows != 0) {
				// 查询总数语句
				String strTotalSql = "select count(1) totalNum from " + strTable + " where 1=1 " + strFilter;

				System.out.println("SQL:" + strTotalSql);

				// 查询总数
				ResultSet rsTotal = oBaseFactory.Query(strTotalSql, requestEntity);

				// 查询总页数
				while (rsTotal.next()) {
					iTotal = Common.toPraseInt(rsTotal.getString("totalNum"), 0);
				}
				;

				strSql = oBaseFactory.GetSqlByPage(strTable, strColumns, strFilter, strSortName, strSortOrder, iPage,
						iRows);

				// System.out.println(strSql);
			} else {
				strSql = oBaseFactory.GetSql(strTable, strColumns, strFilter, strSortName, strSortOrder);
			}

			System.out.println("SQL:" + strSql);
			// 返回结果
			String strResult = "";
			String strRows = "";
			// int iIndex = 1;

			// 验证返回结果
//			if (!requestEntity.getMessage().isEmpty()) {
//				return requestEntity;
//			}

			// System.out.println(requestEntity.getDBConnection().get("jdbc-url").toLowerCase());

			if (requestEntity.getDBConnection().get("jdbc-url").toLowerCase().contains("gauss")) {

				// System.out.println("gauss");

				rsEx = oBaseFactory.QueryEx(strSql, requestEntity);

				while (rsEx.next()) {

					String strRow = "";

					for (String strColumn : strColumnList.keySet()) {
						Object strValue = "";
						String strType = strColumnList.get(strColumn).get(1);
						String strFormat = strColumnList.get(strColumn).get(2);
						// System.out.println("Column:" + strColumn + ",Type:" + strType + ",Format:" +
						// strFormat);
						if (strType.equals("D")) {
							// 日期类型
							strValue = DateTime.toString(rsEx.getString(strColumn), strFormat);

							strRow += "\"" + strColumn + "\": \"" + strValue + "\",";

						} else if (strType.equals("F")) {
							// 浮点类型
							strValue = Common.toPraseDouble(rsEx.getString(strColumn.toString()), 0);

							if (StringUtils.isNotEmpty(strFormat)) {
								strValue = Common.getNumber(strValue.toString(), Common.toPraseInt(strFormat, 2));
							}

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else if (strType.equals("I")) {
							// 数字类型
							strValue = Common.toPraseInt(rsEx.getString(strColumn.toString()), 0);

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else if (strType.equals("A")) {
							// 数组类型
							strValue = Common.isNullEmpty(rsEx.getString(strColumn.toString()), "");

							if (StringUtils.isEmpty(strValue.toString())) {

								strValue = "[]";
							}

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else {
							// 其他类型
							strValue = Common.isNullEmpty(rsEx.getString(strColumn.toString()), "");

							if (StringUtils.isNotEmpty(strFormat)) {

								strValue = Common.toFormat(strValue.toString(), strFormat);

							}
							// System.out.println(strValue.toString());

							strRow += "\"" + strColumn + "\": \"" + strValue + "\",";

							// System.out.println(strRow.toString());
						}

					}

					if (strRow != "") {
						strRow = strRow.substring(0, strRow.length() - 1);
					}

					strRows += "{" + strRow + "},";

					// iIndex += 1;
				}
			} else {
				// 查询数据
				rs = oBaseFactory.Query(strSql, requestEntity);

				// 封装返回对象
				while (rs.next()) {

					String strRow = "";

					for (String strColumn : strColumnList.keySet()) {
						Object strValue = "";
						String strType = strColumnList.get(strColumn).get(1);
						String strFormat = strColumnList.get(strColumn).get(2);
						// System.out.println("Column:" + strColumn + ",Type:" + strType + ",Format:" +
						// strFormat);
						if (strType.equals("D")) {
							// 日期类型
							strValue = DateTime.toString(rs.getString(strColumn), strFormat);

							strRow += "\"" + strColumn + "\": \"" + strValue + "\",";

						} else if (strType.equals("F")) {
							// 浮点类型
							strValue = Common.toPraseDouble(rs.getString(strColumn.toString()), 0);

							if (StringUtils.isNotEmpty(strFormat)) {
								strValue = Common.getNumber(strValue.toString(), Common.toPraseInt(strFormat, 2));
							}

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else if (strType.equals("I")) {
							// 数字类型
							strValue = Common.toPraseInt(rs.getString(strColumn.toString()), 0);

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else if (strType.equals("A")) {
							// 数组类型
							strValue = Common.isNullEmpty(rs.getString(strColumn.toString()), "");

							if (StringUtils.isEmpty(strValue.toString())) {

								strValue = "[]";
							}

							strRow += "\"" + strColumn + "\": " + strValue + ",";

						} else {
							// 其他类型
							strValue = Common.isNullEmpty(rs.getString(strColumn.toString()), "");

							if (StringUtils.isNotEmpty(strFormat)) {

								strValue = Common.toFormat(strValue.toString(), strFormat);

							}
							// System.out.println(strValue.toString());

							strRow += "\"" + strColumn + "\": \"" + strValue + "\",";

							// System.out.println(strRow.toString());
						}

					}

					if (strRow != "") {
						strRow = strRow.substring(0, strRow.length() - 1);
					}

					strRows += "{" + strRow + "},";

					// iIndex += 1;
				}
			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"total\": \"" + iTotal + "\",";
			strResult += "\"rows\": [" + strRows + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}

			try {
				if (rsEx != null) {
					rsEx.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V2.0.0.0
	 * @version --2020年9月7日
	 * @version --新增方法
	 */
	public ApiEntity Get_2_0(ApiEntity requestEntity) {

		ResultSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");

			if (strConnection.contains("jdbc")) {
				requestEntity.setDBConnection(strConnection);
				System.out.println("Connection:" + strConnection);
			}

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			String strColumns = Util.getColumns_2_0(strParams, oBaseFactory.oDBEntity.getDBUrl());
			Map<String, List<String>> strColumnList = Util.getColumnList_2_0(strParams);

			// System.out.println("Columns:" + strColumns);

			// 查询条件
			String strFilter = Util.getFilter(strParams);

			System.out.println("Filter:" + strFilter);

			// 页面大小
			int iRows = Common.toPraseInt(jsonObject.getString("Rows"), 0);
			// 页码
			int iPage = Common.toPraseInt(jsonObject.getString("Page"), 0);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 分组列名
			String strGroupName = jsonObject.getString("GroupName");
			// 总条数
			int iTotal = 0;

			// 查询语句
			String strSql = "";

			if (iRows != 0) {
				// 查询总数语句
				String strTotalSql = "select count(1) totalNum from " + strTable + " where 1=1 " + strFilter;

				System.out.println("SQL:" + strTotalSql);

				// 查询总数
				ResultSet rsTotal = oBaseFactory.Query(strTotalSql, requestEntity);

				// 查询总页数
				while (rsTotal.next()) {
					iTotal = Common.toPraseInt(rsTotal.getString("totalNum"), 0);
				}
				;

				strSql = oBaseFactory.GetSqlByGroup(strTable, strColumns, strFilter, strGroupName, strSortName, iPage,
						iRows);
			} else {
				strSql = oBaseFactory.GetSqlByGroup(strTable, strColumns, strFilter, strGroupName, strSortName);
			}

			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			String strRows = "";
			// int iIndex = 1;

			// 封装返回对象
			while (rs.next()) {

				String strRow = "";

				for (String strColumn : strColumnList.keySet()) {
					Object strValue = "";
					String strColName = strColumn;
					String strType = strColumnList.get(strColumn).get(1);
					String strFormat = strColumnList.get(strColumn).get(2);
					String strFunction = strColumnList.get(strColumn).get(3);
					String strAliasName = "";

					if (StringUtils.isNotEmpty(strFunction)) {
						strColName = strColumn + "_" + strFunction;
					}

					for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
						if (rs.getMetaData().getColumnLabel(i).equals(strColName)) {
							strAliasName = rs.getMetaData().getColumnName(i);
						}
					}

					// System.out.println("ColName：" + strAliasName);

					// System.out.println("Column:" + strColumn + ",Type:" + strType + ",Format:" +
					// strFormat);
					if (strType.equals("D")) {
						// 日期类型
						strValue = DateTime.toString(rs.getString(strAliasName), strFormat);

						strRow += "\"" + strColName + "\": \"" + strValue + "\",";

					} else if (strType.equals("F")) {
						// 浮点类型
						strValue = Common.toPraseDouble(rs.getString(strAliasName.toString()), 0);

						if (StringUtils.isNotEmpty(strFormat)) {
							strValue = Common.getNumber(strValue.toString(), Common.toPraseInt(strFormat, 2));
						}

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else if (strType.equals("I")) {
						// 数字类型
						strValue = Common.toPraseInt(rs.getString(strAliasName.toString()), 0);

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else if (strType.equals("A")) {
						// 数组类型
						strValue = Common.isNullEmpty(rs.getString(strAliasName.toString()), "");

						if (StringUtils.isEmpty(strValue.toString())) {

							strValue = "[]";
						}

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else {
						// 其他类型
						strValue = Common.isNullEmpty(rs.getString(strAliasName.toString()), "");

						if (StringUtils.isNotEmpty(strFormat)) {

							strValue = Common.toFormat(strValue.toString(), strFormat);

						}
						// System.out.println(strValue.toString());

						strRow += "\"" + strColName + "\": \"" + strValue + "\",";

						// System.out.println(strRow.toString());
					}

				}

				if (strRow != "") {
					strRow = strRow.substring(0, strRow.length() - 1);
				}

				strRows += "{" + strRow + "},";

				// iIndex += 1;
			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"total\": \"" + iTotal + "\",";
			strResult += "\"rows\": [" + strRows + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V2.0.0.0
	 * @version --2020年9月7日
	 * @version --新增方法
	 */
	public ApiEntity Get_3_0(ApiEntity requestEntity) {

		CachedRowSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取表名
			String strTable = jsonObject.getString("Table");

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			Map<String, List<String>> strColumnList = Util.getColumnList_3_0(strParams);

			// System.out.println("Columns:" + strColumns);

			System.out.println("Params:" + strParams);

			// 连接语句
			String strJoinUnion = Util.getJoinUnion(strParams);

			System.out.println("JoinUnion:" + strJoinUnion);

			// 查询条件
			String strFilter = Util.getFilter(strParams);

			System.out.println("Filter:" + strFilter);

			// 页面大小
			int iRows = Common.toPraseInt(jsonObject.getString("Rows"), 0);
			// 页码
			int iPage = Common.toPraseInt(jsonObject.getString("Page"), 0);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 分组列名
			String strGroupName = jsonObject.getString("GroupName");
			// 总条数
			int iTotal = 0;

			// 查询语句
			String strSql = "";

			if (iRows != 0) {
				// 查询总数语句
				String strTotalSql = "select count(1) totalNum from " + strTable + strJoinUnion + " where 1=1 "
						+ strFilter;

				System.out.println("SQL:" + strTotalSql);

				// 查询总数
				ResultSet rsTotal = oBaseFactory.Query(strTotalSql, requestEntity);

				// 查询总页数
				while (rsTotal.next()) {
					iTotal = Common.toPraseInt(rsTotal.getString("totalNum"), 0);
				}
				;

				strSql = oBaseFactory.GetSqlByJoin(strTable, strJoinUnion, strColumnList, strFilter, strGroupName,
						strSortName, iPage, iRows);
			} else {
				strSql = oBaseFactory.GetSqlByJoin(strTable, strJoinUnion, strColumnList, strFilter, strGroupName,
						strSortName);
			}

			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			String strRows = "";
			// int iIndex = 1;

			// 封装返回对象
			while (rs.next()) {

				String strRow = "";

				for (String strColumn : strColumnList.keySet()) {
					Object strValue = "";
					String strColName = strColumn;
					String strType = strColumnList.get(strColumn).get(1);
					String strFormat = strColumnList.get(strColumn).get(2);
					String strAliasName = "";

					for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
						if (rs.getMetaData().getColumnLabel(i).equals(strColName)) {
							strAliasName = rs.getMetaData().getColumnName(i);
						}
					}

					// System.out.println("Column:" + strColumn + ",Type:" + strType + ",Format:" +
					// strFormat);

					if (strType.equals("D")) {
						// 日期类型
						strValue = DateTime.toString(rs.getString(strColName), strFormat);

						strRow += "\"" + strColName + "\": \"" + strValue + "\",";

					} else if (strType.equals("F")) {
						// 浮点类型
						strValue = Common.toPraseDouble(rs.getString(strColName.toString()), 0);

						if (StringUtils.isNotEmpty(strFormat)) {
							strValue = Common.getNumber(strValue.toString(), Common.toPraseInt(strFormat, 2));
						}

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else if (strType.equals("I")) {
						// 数字类型
						strValue = Common.toPraseInt(rs.getString(strColName.toString()), 0);

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else if (strType.equals("A")) {
						// 数组类型
						strValue = Common.isNullEmpty(rs.getString(strColName.toString()), "");

						if (StringUtils.isEmpty(strValue.toString())) {

							strValue = "[]";
						} else {
							if (StringUtils.isNotEmpty(strFormat)) {
								strValue = Common.toArrayFormat(strValue.toString(), strFormat);
							}
						}

						strRow += "\"" + strColName + "\": " + strValue + ",";

					} else {
						// 其他类型
						strValue = Common.isNullEmpty(rs.getString(strAliasName.toString()), "");

						if (StringUtils.isNotEmpty(strFormat)) {

							strValue = Common.toFormat(strValue.toString(), strFormat);

						}
						// System.out.println(strValue.toString());

						strRow += "\"" + strColName + "\": \"" + strValue + "\",";

						// System.out.println(strRow.toString());
					}

				}

				if (strRow != "") {
					strRow = strRow.substring(0, strRow.length() - 1);
				}

				strRows += "{" + strRow + "},";

				// iIndex += 1;
			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"total\": \"" + iTotal + "\",";
			strResult += "\"rows\": [" + strRows + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2021年5月20日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity GetEx_1_0(ApiEntity requestEntity) {

		CachedRowSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");
			// 获取类型
			String strDataType = jsonObject.getString("DataType");

			// 验证数据链接不允许为空
			if (StringUtils.isEmpty(strConnection)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("数据链接不能为空!");
			}

			// 数据链接
			// Map<String, Map<String, String>> oDataSourceMap =
			// Util.getConnection(strConnection);

			if (strConnection.contains("jdbc")) {
				requestEntity.setDBConnection(strConnection);
			} else {
				requestEntity.setDBType(strConnection);
			}

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strColumnList = Util.getColumnList_4_0(strParams);
			// 查询条件
			Map<Integer, List<String>> oFilterList = Util.getFilterList(strParams);
			String strFilter = Util.getFilter(oFilterList);
			// 连接语句
			String strJoinUnion = Util.getJoinUnion(strParams);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 聚合列名
			String strGroupName = jsonObject.getString("GroupName");

			// 查询语句
			String strSql = oBaseFactory.GetSql(strTable, strColumnList, strFilter, strSortName, strGroupName,
					strJoinUnion);

			// System.out.println("Columns:" + strColumns);
			System.out.println("DataType:" + strDataType);
			System.out.println("Filter:" + strFilter);
			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			String strRows = "";

			// 封装返回对象
			while (rs.next()) {

				if (strDataType.equals("Table")) {

					String strRow = "";
					int iIndex = 0;

					for (String strColumn : strColumnList.keySet()) {

						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						if (iIndex == 0) {
							strRow += "\"\":"
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat)
									+ ",";
						} else {
							strRow += "\"" + strAliasName.toString() + "\":"
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat)
									+ ",";
						}

						iIndex += 1;
					}

					strRow = strRow.substring(0, strRow.length() - 1);

					strRows += "{" + strRow + "},";

				} else if (strDataType.equals("Pie")) {

					String strRow = "\"name\":";

					int iIndex = 0;
					for (String strColumn : strColumnList.keySet()) {

						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						if (iIndex == 0) {
							strRow += ""
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat)
									+ ",\"value\":";
						} else {
							strRow += ""
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat);
						}
						if (iIndex >= 1) {
							break;
						}
						iIndex += 1;
					}

					strRows += "{" + strRow + "},";

				} else {

					String strRow = "\"key\":";

					int iIndex = 0;
					for (String strColumn : strColumnList.keySet()) {

						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						if (iIndex == 0) {
							strRow += ""
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat)
									+ ",\"value\":[";
						} else {
							strRow += ""
									+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat)
									+ ",";
						}

						iIndex += 1;
					}

					strRow = strRow.substring(0, strRow.length() - 1);
					strRow += "]";

					strRows += "{" + strRow + "},";
				}

			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"code\": \"" + requestEntity.getCode() + "\",";
			strResult += "\"data\": [" + strRows + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2021年5月20日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity GetEx_1_1(ApiEntity requestEntity) {

		CachedRowSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");
			// 获取类型
			String strDataType = jsonObject.getString("DataType");
			// 一级分类
			String strCategoryName = "";
			// 二级分类
			String strSecondCategoryName = "";

			try {

				// 获取类型
				String strCategory = jsonObject.getString("Category");

				// 一级分类
				strCategoryName = strCategory.split("\\|")[0];
				// 二级分类
				strSecondCategoryName = strCategory.split("\\|")[1];

			} catch (Exception ex) {
			}

			// System.out.println("CategoryName:" + strCategoryName);
			// System.out.println("SecondCategoryName:" + strSecondCategoryName);

			// 验证数据链接不允许为空
			if (StringUtils.isEmpty(strConnection)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("数据链接不能为空!");
			}

			if (strConnection.contains("jdbc")) {
				requestEntity.setDBConnection(strConnection);
			} else {
				requestEntity.setDBType(strConnection);
			}

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strColumnList = Util.getColumnList_4_0(strParams);
			// 查询条件
			Map<Integer, List<String>> oFilterList = Util.getFilterList(strParams);
			String strFilter = Util.getFilter(oFilterList);
			// 连接语句
			String strJoinUnion = Util.getJoinUnion(strParams);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 聚合列名
			String strGroupName = jsonObject.getString("GroupName");

			// 查询语句
			String strSql = oBaseFactory.GetSql(strTable, strColumnList, strFilter, strSortName, strGroupName,
					strJoinUnion);

			// System.out.println("Columns:" + strColumns);
			// System.out.println("DataType:" + strDataType);
			// System.out.println("Filter:" + strFilter);
			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			StringBuilder strRows = new StringBuilder();
			String strGroup = "";
			Map<String, List<String>> singleList = new LinkedHashMap<String, List<String>>();
			Map<String, Map<String, List<String>>> multiList = new LinkedHashMap<String, Map<String, List<String>>>();
			int iGroup = 0;

			if (strDataType.equals("Table")) {
				// 封装返回对象
				while (rs.next()) {

					String strCategory1 = "";
					String strCategory2 = "";

					List<String> oIndexList = new ArrayList<String>();
					int iIndex = 0;
					for (String strColumn : strColumnList.keySet()) {

						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						// System.out.println("Colunms:" + strColumn + ",AliasName:" + strAliasName);

						if (StringUtils.isNotEmpty(strSecondCategoryName)) {

							if (iIndex == 0) {
								// 一级分类
								strCategory1 = rs.getString(strAliasName).toString().trim();
							} else if (iIndex == 1) {
								// 二级分类
								strCategory2 = rs.getString(strAliasName).toString().trim();
							} else {
								// 指标
								oIndexList.add(
										Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat));

								if (iGroup == 0) {
									strGroup += "\"" + strColumn + "\",";
								}
							}
						} else {

							if (iIndex == 0) {
								// 一级分类
								strCategory1 = rs.getString(strAliasName).toString().trim();
							} else {
								// 指标
								oIndexList.add(
										Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat));

								if (iGroup == 0) {
									strGroup += "\"" + strColumn + "\",";
								}
							}
						}

						iIndex += 1;
					}

					if (StringUtils.isNotEmpty(strSecondCategoryName)) {

						if (multiList.containsKey(strCategory1)) {
							multiList.get(strCategory1).put(strCategory2, oIndexList);
						} else {
							Map<String, List<String>> oSecondCategoryList = new LinkedHashMap<String, List<String>>();

							oSecondCategoryList.put(strCategory2, oIndexList);

							multiList.put(strCategory1, oSecondCategoryList);
						}
					} else {
						singleList.put(strCategory1, oIndexList);
					}

					iGroup += 1;
				}

				if (StringUtils.isNotEmpty(strSecondCategoryName)) {

					for (String strCategoryValue : multiList.keySet()) {
						strRows.append("{\"key\":\"" + strCategoryValue + "\",\"value\":[");

						for (String strSecondCategoryValue : multiList.get(strCategoryValue).keySet()) {
							strRows.append("{\"key\":\"" + strSecondCategoryValue + "\",\"value\":[");

							StringBuilder strValue = new StringBuilder();
							for (String strIndexValue : multiList.get(strCategoryValue).get(strSecondCategoryValue)) {
								strValue.append("\"" + strIndexValue + "\",");

							}

							if (strValue.length() > 0) {
								strValue.delete(strValue.length() - 1, strValue.length());
							}

							strRows.append(strValue + "]},");
						}

						if (strRows.length() > 0) {
							strRows.delete(strRows.length() - 1, strRows.length());
						}

						strRows.append("]},");
					}
				} else {

					for (String strCategoryValue : singleList.keySet()) {
						strRows.append("{\"key\":\"" + strCategoryValue + "\",\"value\":[");

						for (String strIndexValue : singleList.get(strCategoryValue)) {
							strRows.append("\"" + strIndexValue + "\",");
						}

						if (strRows.length() > 0) {
							strRows.delete(strRows.length() - 1, strRows.length());
						}

						strRows.append("]},");
					}
				}

			} else if (strDataType.equals("Label")) {
				// 封装返回对象
				while (rs.next()) {

					for (String strColumn : strColumnList.keySet()) {
						String strRow = "";
						String strColumnName = strColumnList.get(strColumn).get(1);
						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						strRow = "\"name\":\"" + strColumnName + "\",\"value\":"
								+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat);

						strRows.append("{" + strRow + "},");
					}

				}
			} else if (strDataType.equals("Data")) {
				// 封装返回对象
				while (rs.next()) {

					String strRow = "";

					for (String strColumn : strColumnList.keySet()) {

						String strColumnName = strColumnList.get(strColumn).get(1);
						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						strRow += "\"" + strAliasName + "\":\""
								+ Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType, strFormat)
								+ "\",";

					}
					strRows.append("{" + strRow.substring(0, strRow.length() - 1) + "},");

				}
			} else {
				// 封装返回对象
				while (rs.next()) {

					String strCategory1 = "";
					String strCategory2 = "";

					List<String> oIndexList = new ArrayList<String>();
					int iIndex = 0;
					for (String strColumn : strColumnList.keySet()) {

						String strType = strColumnList.get(strColumn).get(2);
						String strFormat = strColumnList.get(strColumn).get(3);
						String strAliasName = "";

						for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
							if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
								strAliasName = rs.getMetaData().getColumnName(i);
							}
						}

						// System.out.println("Colunms:" + strColumn + ",AliasName:" + strAliasName);

						// System.out.println("ColunmSizes:" + strColumnList.size());

						if (strColumnList.size() == 3) {

							if (iIndex == 0) {
								// 一级分类
								strCategory1 = Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType,
										strFormat);

								System.out.println("strCategory1:" + strCategory1);
							} else if (iIndex == 1) {
								// 二级分类
								strCategory2 = Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType,
										strFormat);

								System.out.println("strCategory2:" + strCategory2);
							} else {
								// 指标
								oIndexList.add(Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType,
										strFormat));

								System.out.println("oIndexList:" + oIndexList);

							}
						} else {

							if (iIndex == 0) {
								// 一级分类
								strCategory1 = Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType,
										strFormat);
							} else {
								// 指标

								oIndexList.add(Util.analysisColumn_2_0(rs.getString(strAliasName.toString()), strType,
										strFormat));
							}

							if (iIndex == 0) {
								strGroup = "\"" + strColumn + "\",";
							}
						}

						iIndex += 1;
					}

					if (strColumnList.size() == 3) {

						if (multiList.containsKey(strCategory1)) {
							multiList.get(strCategory1).put(strCategory2, oIndexList);
						} else {
							Map<String, List<String>> oSecondCategoryList = new LinkedHashMap<String, List<String>>();

							oSecondCategoryList.put(strCategory2, oIndexList);

							multiList.put(strCategory1, oSecondCategoryList);
						}
					} else {
						singleList.put(strCategory1, oIndexList);
					}
				}

				if (strColumnList.size() == 3) {

					Map<String, List<String>> oGroupList = new LinkedHashMap<String, List<String>>();

					for (String strCategoryValue : multiList.keySet()) {
						if (oGroupList.size() < multiList.get(strCategoryValue).size()) {
							oGroupList = multiList.get(strCategoryValue);
						}
					}

					for (String strCategoryValue : multiList.keySet()) {
						strRows.append("{\"key\":\"" + strCategoryValue + "\",\"value\":[");

						for (String strSecondCategoryValue : oGroupList.keySet()) {

							if (multiList.get(strCategoryValue).containsKey(strSecondCategoryValue)) {
								for (String strIndexValue : multiList.get(strCategoryValue)
										.get(strSecondCategoryValue)) {
									strRows.append("\"" + strIndexValue + "\",");
								}
							} else {
								strRows.append("\"0\",");
							}

							if (iGroup == 0) {
								strGroup += "\"" + strSecondCategoryValue + "\",";
							}
						}

						if (strRows.length() > 0) {
							strRows.delete(strRows.length() - 1, strRows.length());
						}

						strRows.append("]},");

						iGroup += 1;
					}

				} else {

					if (strDataType.equals("Pie")) {
						for (String strCategoryValue : singleList.keySet()) {
							strRows.append("{\"name\":\"" + strCategoryValue + "\",\"value\":[");

							for (String strIndexValue : singleList.get(strCategoryValue)) {
								strRows.append("\"" + strIndexValue + "\",");
							}

							if (strRows.length() > 0) {
								strRows.delete(strRows.length() - 1, strRows.length());
							}

							strRows.append("]},");
						}
					} else {
						for (String strCategoryValue : singleList.keySet()) {
							strRows.append("{\"key\":\"" + strCategoryValue + "\",\"value\":[");

							for (String strIndexValue : singleList.get(strCategoryValue)) {
								strRows.append("\"" + strIndexValue + "\",");
							}

							if (strRows.length() > 0) {
								strRows.delete(strRows.length() - 1, strRows.length());
							}

							strRows.append("]},");
						}
					}
				}
			}

			if (strRows.length() > 0) {
				strRows.delete(strRows.length() - 1, strRows.length());
			}

			if (strGroup != "") {
				strGroup = strGroup.substring(0, strGroup.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"code\": \"" + requestEntity.getCode() + "\",";
			strResult += "\"data\": [" + strRows.toString() + "],";
			strResult += "\"group\": [" + strGroup + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2022年9月15日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity GetEx_1_3(ApiEntity requestEntity) {

		CachedRowSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");
			// 获取类型
			String strDataType = jsonObject.getString("DataType");
			// 一级分类
			String strCategoryName = "";
			// 二级分类
			String strSecondCategoryName = "";

			try {

				// 获取类型
				String strCategory = jsonObject.getString("Category");

				// 一级分类
				strCategoryName = strCategory.split("\\|")[0];
				// 二级分类
				strSecondCategoryName = strCategory.split("\\|")[1];

			} catch (Exception ex) {
			}

			// System.out.println("CategoryName:" + strCategoryName);
			// System.out.println("SecondCategoryName:" + strSecondCategoryName);

			// 验证数据链接不允许为空
			if (StringUtils.isEmpty(strConnection)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("数据链接不能为空!");
			}

			// requestEntity.setDBConnection(strConnection);

			requestEntity.setDBType(strConnection);

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strColumnList = Util.getColumnList_4_0(strParams);
			// 查询条件
			Map<Integer, List<String>> oFilterList = Util.getFilterList(strParams);
			String strFilter = Util.getFilter(oFilterList);
			// 连接语句
			String strJoinUnion = Util.getJoinUnion(strParams);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 聚合列名
			String strGroupName = jsonObject.getString("GroupName");

			// 查询语句
			String strSql = oBaseFactory.GetSql(strTable, strColumnList, strFilter, strSortName, strGroupName,
					strJoinUnion);

			// System.out.println("Columns:" + strColumns);
			// System.out.println("DataType:" + strDataType);
			// System.out.println("Filter:" + strFilter);
			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			StringBuilder strRows = new StringBuilder();
			String strGroup = "";
			int iTotal = 0;

			Map<String, RSEntity> resultList = new LinkedHashMap<String, RSEntity>();

			for (String strColumn : strColumnList.keySet()) {

				RSEntity result = new RSEntity();

				result.setColumnName(strColumnList.get(strColumn).get(1));
				result.setType(strColumnList.get(strColumn).get(2));
				result.setFormat(strColumnList.get(strColumn).get(3));

				resultList.put(result.getColumnName(), result);
			}

			// 封装返回对象
			while (rs.next()) {

				for (String strColumn : strColumnList.keySet()) {
					String strRow = "";
					String strColumnName = strColumnList.get(strColumn).get(1);

					String strAliasName = "";

					for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
						if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
							strAliasName = rs.getMetaData().getColumnName(i);
						}
					}

					resultList.get(strColumnName).getResultList().add(rs.getString(strAliasName.toString()));

				}

				iTotal += 1;
			}

			int iCount = 0;
			for (String strColumnName : resultList.keySet()) {

				strRows.append("{");
				strRows.append("\"key\":\"" + strColumnName + "\",");
				strRows.append("\"name\":\"" + resultList.get(strColumnName).getAliasName() + "\",");
				strRows.append("\"value\":[");

				int iLength = 0;
				for (String strValue : resultList.get(strColumnName).getResultList()) {

					strRows.append(Util.analysisColumn(strValue, resultList.get(strColumnName).getType(),
							resultList.get(strColumnName).getFormat()));

					if (iLength < resultList.get(strColumnName).getResultList().size() - 1) {
						strRows.append(",");
					}
					iLength += 1;
				}

				strRows.append("]");
				strRows.append("}");

				if (iCount < resultList.size() - 1) {
					strRows.append(",");
				}
				iCount += 1;
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"total\": \"" + iTotal + "\",";
			strResult += "\"data\": [" + strRows.toString() + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2021年5月20日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity GetEx_1_2(ApiEntity requestEntity) {

		CachedRowSet rs = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");
			// 获取类型
			String strDataType = jsonObject.getString("DataType");

			// 验证数据链接不允许为空
			if (StringUtils.isEmpty(strConnection)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("数据链接不能为空!");
			}

			// 数据链接
			// Map<String, Map<String, String>> oDataSourceMap =
			// Util.getConnection(strConnection);

			requestEntity.setDBConnection(strConnection);

			// 验证表名不允许为空
			if (StringUtils.isEmpty(strTable)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("表名不能为空!");
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strColumnList = Util.getColumnList_4_0(strParams);
			// 查询条件
			Map<Integer, List<String>> oFilterList = Util.getFilterList(strParams);
			String strFilter = Util.getFilter(oFilterList);
			// 连接语句
			String strJoinUnion = Util.getJoinUnion(strParams);
			// 排序列名
			String strSortName = jsonObject.getString("SortName");
			// 聚合列名
			String strGroupName = jsonObject.getString("GroupName");

			// 查询语句
			String strSql = oBaseFactory.GetSql(strTable, strColumnList, strFilter, strSortName, strGroupName,
					strJoinUnion);

			// System.out.println("Columns:" + strColumns);
			System.out.println("DataType:" + strDataType);
			System.out.println("Filter:" + strFilter);
			System.out.println("SQL:" + strSql);

			// 查询数据
			rs = oBaseFactory.Query(strSql, requestEntity);

			// 验证返回结果
			if (!requestEntity.getMessage().isEmpty()) {
				return requestEntity;
			}

			// 返回结果
			String strResult = "";
			String strRows = "";

			// 封装返回对象
			while (rs.next()) {

				for (String strColumn : strColumnList.keySet()) {
					String strRow = "";
					String strColumnName = strColumnList.get(strColumn).get(1);
					String strType = strColumnList.get(strColumn).get(2);
					String strFormat = strColumnList.get(strColumn).get(3);
					String strAliasName = "";

					for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
						if (rs.getMetaData().getColumnLabel(i).equals(strColumn)) {
							strAliasName = rs.getMetaData().getColumnName(i);
						}
					}

					strRow = "\"name\":\"" + strColumnName + "\",\"value\":"
							+ Util.analysisColumn(rs.getString(strAliasName.toString()), strType, strFormat);

					strRows += "{" + strRow + "},";
				}

			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"code\": \"" + requestEntity.getCode() + "\",";
			strResult += "\"data\": [" + strRows + "],";
			strResult += "\"group\": []";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 通用查询接口
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2021年5月27日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity GetQuota_1_0(ApiEntity requestEntity) {

		ResultSet rs = null;
		CachedRowSet rsType = null;
		CachedRowSet rsCache = null;
		CachedRowSet rsSjj = null;
		CachedRowSet rsCategory = null;
		CachedRowSet rsSecondCategory = null;
		CachedRowSet rsIndex = null;
		CachedRowSet rsTable = null;
		CachedRowSet rsSecondTable = null;
		CachedRowSet rsCode = null;

		try {
			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取表名
			String strTable = jsonObject.getString("Table");
			// 获取类型
			String strDataType = jsonObject.getString("DataType");

			// 验证数据链接不允许为空
			if (StringUtils.isEmpty(strConnection)) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("数据链接不能为空!");
			}

			// 数据链接
			// Map<String, Map<String, String>> oDataSourceMap =
			// Util.getConnection(strConnection);

			requestEntity.setDBType(strConnection);

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strParamList = Util.getColumnList_4_0(strParams);
			Map<String, List<String>> strColumnList = new LinkedHashMap<String, List<String>>();

			String strID = strParamList.get("id").get(0);
			String strIndex = strParamList.get("index").get(0);
			String strCategory = strParamList.get("category").get(0);
			String strSecondCategory = "";
			String strDBConnection = strParamList.get("dbConnection").get(0);
			String strSql = "";
			String strSjjID = "";
			String strCacheSearchSql = "";
			String strCategoryName = "";
			String strCategoryCode = "";
			String strSecondCategoryName = "";
			String strSecondCategoryCode = "";
			List<String> aryIndexNames = new ArrayList<String>();
			String strViewSql = "";
			String strSearchSql = "";
			String strFlmx = "";
			String strIndexName = "";
			String strQSIndex = "0";
			String strResult = "";
			String strRows = "";
			String strGroup = "";

			if (strParamList.containsKey("secondCategory")) {
				strSecondCategory = strParamList.get("secondCategory").get(0);
			}

			// System.out.println("SecondCategory:" + strSecondCategory);

			// 1.判断类型
			strSql = "select lx from t_zbtx_zb where id=" + strID;

			System.out.println("判断类型SQL:" + strSql);

			rsType = oBaseFactory.Query(strSql, requestEntity);

			while (rsType.next()) {
				strQSIndex = rsType.getString("lx");
			}

			// 如果是趋势
			if (strQSIndex.equals("1")) {

				requestEntity = queryTendency(requestEntity, strSjjID);

			} else {
				// 1.查询数据集ID、数据集SQL
				strSql = "select t_zbtx_zb.sjjid,sjjsql from t_zbtx_zb left join sjj on sjj.id=t_zbtx_zb.sjjid where t_zbtx_zb.id="
						+ strID;

				System.out.println("数据集SQL:" + strSql);

				rsSjj = oBaseFactory.Query(strSql, requestEntity);

				while (rsSjj.next()) {
					strSjjID = rsSjj.getString("sjjid");
					strViewSql = rsSjj.getString("sjjsql");
				}

				// 2.查询分类
				strSql = "select flmc,bzddm,bzddmbm from flmx left join sjj_yxdx_zd on flmx.flzd=sjj_yxdx_zd.zdid and flmx.sjjid=sjj_yxdx_zd.sjjid where flmx.flzd="
						+ strCategory + " and flmx.zbsid=" + strID;

				System.out.println("分类SQL:" + strSql);

				rsCategory = oBaseFactory.Query(strSql, requestEntity);

				while (rsCategory.next()) {
					strFlmx = rsCategory.getString("flmc");
					strCategoryName = rsCategory.getString("bzddmbm");
					strCategoryCode = rsCategory.getString("bzddm");

					strSearchSql += "a." + rsCategory.getString("bzddmbm") + " " + rsCategory.getString("flmc") + " ";

					List<String> oAttributeList = new ArrayList<String>();
					oAttributeList.add(rsCategory.getString("bzddmbm"));
					oAttributeList.add(rsCategory.getString("flmc"));
					oAttributeList.add("C");
					oAttributeList.add("");

					strColumnList.put(rsCategory.getString("flmc"), oAttributeList);

				}

				// 查询二级分类
				if (StringUtils.isNotEmpty(strSecondCategory)) {
					strSql = "select flmc,bzddm,bzddmbm from flmx left join sjj_yxdx_zd on flmx.flzd=sjj_yxdx_zd.zdid and flmx.sjjid=sjj_yxdx_zd.sjjid where flmx.flzd="
							+ strSecondCategory + " and flmx.zbsid=" + strID;

					System.out.println("二级分类SQL:" + strSql);

					rsSecondCategory = oBaseFactory.Query(strSql, requestEntity);

					while (rsSecondCategory.next()) {
						strSecondCategoryName = rsSecondCategory.getString("bzddmbm");
						strSecondCategoryCode = rsSecondCategory.getString("bzddm");

						strSearchSql += ",a." + rsSecondCategory.getString("bzddmbm") + " "
								+ rsSecondCategory.getString("flmc") + " ";

						List<String> oAttributeList = new ArrayList<String>();
						oAttributeList.add(rsSecondCategory.getString("bzddmbm"));
						oAttributeList.add(rsSecondCategory.getString("flmc"));
						oAttributeList.add("C");
						oAttributeList.add("");

						strColumnList.put(rsSecondCategory.getString("flmc"), oAttributeList);

					}
				}

				// 3.查询指标
				strSql = "select hzlx,bzddmbm,zbmc from zb left join sjj_yxdx_zd on zb.zdid=sjj_yxdx_zd.zdid and zb.sjjid=sjj_yxdx_zd.sjjid where zb.zdid in ("
						+ strIndex.replace("[", "").replace("]", "") + ") and zb.zbsid=" + strID;

				System.out.println("指标SQL:" + strSql);

				rsIndex = oBaseFactory.Query(strSql, requestEntity);

				while (rsIndex.next()) {
					String strIndexCol = rsIndex.getString("bzddmbm");
					strIndexName = rsIndex.getString("zbmc");
					aryIndexNames.add(strIndexName);
					String strFunction = rsIndex.getString("hzlx");

					switch (strFunction) {
					case "1":
						strSearchSql += ",count(a." + strIndexCol + ") " + strIndexName + "";
						break;
					case "2":
						strSearchSql += ",count(distinct a." + strIndexCol + ") " + strIndexName + "";
						break;
					case "3":
						strSearchSql += ",sum(a." + strIndexCol + ") " + strIndexName + "";
						break;
					case "4":
						strSearchSql += ",avg(a." + strIndexCol + ") " + strIndexName + "";
						break;
					}

					List<String> oAttributeList = new ArrayList<String>();
					oAttributeList.add(strIndexCol);
					oAttributeList.add(strIndexName);
					oAttributeList.add("C");
					oAttributeList.add("");

					strColumnList.put(strIndexName, oAttributeList);
				}

				// 判断是否有缓存表
				String strCacheSql = "select cxsql from t_bm_ui where sjjid=" + strSjjID + " and flzdid=" + strCategory
						+ " and zbzdid=" + strIndex.replace("[", "").replace("]", "") + " and flmc='" + strFlmx
						+ "' and zbmc='" + strIndexName + "'";

				System.out.println("缓存SQL:" + strCacheSql);

				rsCache = oBaseFactory.Query(strCacheSql, requestEntity);

				while (rsCache.next()) {

					strCacheSearchSql = rsCache.getString("cxsql");
				}

				if (StringUtils.isNotEmpty(strCacheSearchSql)) {

					if (strParamList.get("rq_0") != null) {
						String strDate = strParamList.get("rq_0").get(0);

						if (StringUtils.isNotEmpty(strDate)) {
							strCacheSearchSql += " where rq = ('" + strDate.substring(0, 7) + "-01'::date)";
						}
					} else {
						SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
						Date date = new Date();
						Calendar calendar = Calendar.getInstance();
						calendar.setTime(date); // 设置为当前时间
						calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
						date = calendar.getTime();
						String dtMonth = df.format(date);

						System.out.println(dtMonth);
						strCacheSearchSql += " where rq = ('" + dtMonth + "-01'::date)";
					}

					if (strParamList.get("qxcode") != null) {
						String strQXCode = strParamList.get("qxcode").get(0);

						strCacheSearchSql += " and xzqhfrcode0 = " + strQXCode;
					}

					strCacheSearchSql += " order by px";

					System.out.println("查询缓存表SQL:" + strCacheSearchSql);

					// 实例化数据库连接
					// requestEntity.setDBConnection(strDBConnection);
					requestEntity.setDBType(strDBConnection);
					oBaseFactory = new BaseFactory(requestEntity);

					// 查询
					rs = oBaseFactory.QueryEx(strCacheSearchSql, requestEntity);

					strColumnList.clear();

					List<String> oAttributeList = new ArrayList<String>();
					oAttributeList.add("name");
					oAttributeList.add("name");
					oAttributeList.add("C");
					oAttributeList.add("");

					strColumnList.put("name", oAttributeList);
					// SELECT xzqhfrname0 as name,a0 FROM sdp_jgj_test.t_jyrybdsjj_jyryhbbdqkjg_02

					String strIndexRealName = strCacheSearchSql.substring(strCacheSearchSql.indexOf(","));
					strIndexRealName = strIndexRealName.substring(1, strIndexRealName.indexOf(" "));
					System.out.println("IndexRealName:" + strIndexRealName);

					List<String> oAttributeList1 = new ArrayList<String>();
					oAttributeList1.add(strIndexRealName);
					oAttributeList1.add(strIndexRealName);
					oAttributeList1.add("C");
					oAttributeList1.add("");

					strColumnList.put(strIndexRealName, oAttributeList1);

				} else {

					// 4.实例化数据库连接
					// requestEntity.setDBConnection(strDBConnection);
					requestEntity.setDBType(strDBConnection);
					oBaseFactory = new BaseFactory(requestEntity);

					// 5.查询编码
					strSql = "select code_table from sdp_jcsj_test.key_code_table where zd_key = '" + strCategoryCode
							+ "'";

					System.out.println("编码表SQL:" + strSql);

					String strCodeTable = "";
					rsTable = oBaseFactory.Query(strSql, requestEntity);
					while (rsTable.next()) {

						strCodeTable = rsTable.getString("code_table").toString();

					}

					strSearchSql += " from(" + strViewSql + ") a ";

					if (StringUtils.isNotEmpty(strSecondCategory)) {

						// 5.查询编码
						strSql = "select code_table from sdp_jcsj_test.key_code_table where zd_key = '"
								+ strSecondCategoryCode + "'";

						System.out.println("二级编码表SQL:" + strSql);

						String strSecondCodeTable = "";
						rsSecondTable = oBaseFactory.Query(strSql, requestEntity);
						while (rsSecondTable.next()) {

							strSecondCodeTable = rsSecondTable.getString("code_table").toString();

						}

						if (StringUtils.isNotEmpty(strCodeTable)) {

							strSearchSql = " select b.name,c.name secondname," + strSearchSql;

							strSearchSql += " left join " + strCodeTable + " b on b.code=a." + strCategoryName;
							strSearchSql += " left join " + strSecondCodeTable + " c on c.code=a."
									+ strSecondCategoryName;
							strSearchSql += " group by a." + strCategoryName + ",a." + strSecondCategoryName
									+ ",b.name,b.px,c.name,c.px";
							strSearchSql += " order by b.px,c.px";
						} else {

							strSearchSql = " select a." + strCategoryName + " as name, a." + strSecondCategoryName
									+ " 'secondname'," + strSearchSql;

							strSearchSql += " group by a." + strCategoryName + ",a." + strSecondCategoryName;
							strSearchSql += " order by a." + strCategoryName + ",a." + strSecondCategoryName;
						}
					} else {
						if (StringUtils.isNotEmpty(strCodeTable)) {
							strSearchSql = " select b.name," + strSearchSql;

							strSearchSql += " left join " + strCodeTable + " b on b.code=a." + strCategoryName;
							strSearchSql += " group by a." + strCategoryName + ",b.name,b.px";
							strSearchSql += " order by b.px";
						} else {

							strSearchSql = " select a." + strCategoryName + " as name," + strSearchSql;

							strSearchSql += " group by a." + strCategoryName;
							strSearchSql += " order by a." + strCategoryName;
						}
					}

					System.out.println("查询SQL:" + strSearchSql);

					// 6.查询
					rs = oBaseFactory.QueryEx(strSearchSql, requestEntity);

				}

				// 返回结果

				int iGroup = 0;
				Map<String, List<String>> singleList = new LinkedHashMap<String, List<String>>();
				Map<String, Map<String, List<String>>> multiList = new LinkedHashMap<String, Map<String, List<String>>>();

				// 封装返回对象
				while (rs.next()) {

					if (strDataType.equals("Table")) {

						String strCategory1 = "";
						String strCategory2 = "";

						List<String> oIndexList = new ArrayList<String>();
						int iIndex = 0;
						for (String strColumn : strColumnList.keySet()) {

							String strType = strColumnList.get(strColumn).get(2);
							String strFormat = strColumnList.get(strColumn).get(3);

							if (StringUtils.isNotEmpty(strSecondCategory)) {

								if (iIndex == 0) {
									// 一级分类
									strCategory1 = rs.getString("name");
								} else if (iIndex == 1) {
									// 二级分类
									strCategory2 = rs.getString("secondname");
								} else {
									// 指标
									oIndexList.add(rs.getString(strColumn));

									if (iGroup == 0) {
										strGroup += "\"" + strColumn + "\",";
									}
								}
							} else {

								if (iIndex == 0) {
									// 一级分类
									strCategory1 = rs.getString("name");
								} else {
									// 指标
									oIndexList.add(rs.getString(strColumn));

									if (iGroup == 0) {
										strGroup += "\"" + strColumn + "\",";
									}
								}
							}

							iIndex += 1;
						}

						if (StringUtils.isNotEmpty(strSecondCategory)) {

							if (multiList.containsKey(strCategory1)) {
								multiList.get(strCategory1).put(strCategory2, oIndexList);
							} else {
								Map<String, List<String>> oSecondCategoryList = new LinkedHashMap<String, List<String>>();

								oSecondCategoryList.put(strCategory2, oIndexList);

								multiList.put(strCategory1, oSecondCategoryList);
							}
						} else {
							singleList.put(strCategory1, oIndexList);
						}

						iGroup += 1;

					} else if (strDataType.equals("Pie")) {

						String strRow = "\"name\":";

						int iIndex = 0;
						for (String strColumn : strColumnList.keySet()) {

							String strType = strColumnList.get(strColumn).get(2);
							String strFormat = strColumnList.get(strColumn).get(3);

							if (iIndex == 0) {

								String strKey = Util.analysisColumn(rs.getString("name"), strType, strFormat);

								strRow += "" + strKey + ",\"value\":";
							} else {
								strRow += "" + Util.analysisColumn(rs.getString(strColumn), strType, strFormat);
							}

							if (iIndex == 0) {
								strGroup = "\"" + strColumn + "\",";
							}

							if (iIndex >= 1) {
								break;
							}
							iIndex += 1;
						}

						strRows += "{" + strRow + "},";

					} else {

						String strRow = "\"key\":";

						int iIndex = 0;
						for (String strColumn : strColumnList.keySet()) {

							String strType = strColumnList.get(strColumn).get(2);
							String strFormat = strColumnList.get(strColumn).get(3);

							if (iIndex == 0) {

								String strKey = Util.analysisColumn(rs.getString("name"), strType, strFormat);

								strRow += "" + strKey + ",\"value\":[";
							} else {

								strRow += "" + Util.analysisColumn(rs.getString(strColumn), strType, strFormat) + ",";
							}

							if (iIndex == 0) {
								strGroup = "\"" + strColumn + "\",";
							}

							iIndex += 1;
						}

						strRow = strRow.substring(0, strRow.length() - 1);
						strRow += "]";

						strRows += "{" + strRow + "},";
					}

				}

				if (strDataType.equals("Table")) {

					if (StringUtils.isNotEmpty(strSecondCategory)) {

						for (String strCategoryValue : multiList.keySet()) {
							strRows += "{\"key\":\"" + strCategoryValue + "\",\"value\":[";

							for (String strSecondCategoryValue : multiList.get(strCategoryValue).keySet()) {
								strRows += "{\"key\":\"" + strSecondCategoryValue + "\",\"value\":[";

								for (String strIndexValue : multiList.get(strCategoryValue)
										.get(strSecondCategoryValue)) {
									strRows += "\"" + strIndexValue + "\",";
								}

								if (iGroup == 0) {
									strGroup += "\"" + strSecondCategoryValue + "\",";
								}

								if (strRows != "") {
									strRows = strRows.substring(0, strRows.length() - 1);
								}

								strRows += "]},";
							}

							if (strRows != "") {
								strRows = strRows.substring(0, strRows.length() - 1);
							}

							strRows += "]},";

							iGroup += 1;
						}
					} else {

						for (String strCategoryValue : singleList.keySet()) {
							strRows += "{\"key\":\"" + strCategoryValue + "\",\"value\":[";

							for (String strIndexValue : singleList.get(strCategoryValue)) {
								strRows += "\"" + strIndexValue + "\",";
							}

							if (strRows != "") {
								strRows = strRows.substring(0, strRows.length() - 1);
							}

							strRows += "]},";
						}
					}
				}

				if (strRows != "") {
					strRows = strRows.substring(0, strRows.length() - 1);
				}

				if (aryIndexNames.size() > 0) {

					strGroup = "";

					for (String strName : aryIndexNames) {
						strGroup += "\"" + strName + "\",";
					}
				}

				if (strGroup != "") {
					strGroup = strGroup.substring(0, strGroup.length() - 1);
				}

				// 封装返回结果
				strResult += "{";
				strResult += "\"code\": \"" + requestEntity.getCode() + "\",";
				strResult += "\"data\": [" + strRows + "],";
				strResult += "\"group\": [" + strGroup + "]";
				strResult += "}";

				requestEntity.setReturnType(false);
				requestEntity.setResult(strResult);
			}

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
				if (rsType != null) {
					rsType.close();
				}
				if (rsSjj != null) {
					rsSjj.close();
				}
				if (rsCategory != null) {
					rsCategory.close();
				}
				if (rsSecondCategory != null) {
					rsSecondCategory.close();
				}
				if (rsIndex != null) {
					rsIndex.close();
				}
				if (rsTable != null) {
					rsTable.close();
				}
				if (rsSecondTable != null) {
					rsSecondTable.close();
				}
				if (rsCode != null) {
					rsCode.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	public ApiEntity queryTendency(ApiEntity requestEntity, String strSjjID) {
		ResultSet rs = null;
		CachedRowSet rsCache = null;
		CachedRowSet rsSjj = null;
		CachedRowSet rsCategory = null;
		CachedRowSet rsSecondCategory = null;
		CachedRowSet rsIndex = null;
		CachedRowSet rsTable = null;
		CachedRowSet rsSecondTable = null;
		CachedRowSet rsCode = null;

		try {
			String strParams = requestEntity.getParams();

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);
			// 获取数据库链接
			String strConnection = "";
			try {
				strConnection = jsonObject.getString("Connection");
			} catch (Exception ex) {
			}
			// 获取类型
			String strDataType = jsonObject.getString("DataType");

			requestEntity.setDBType(strConnection);

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 查询的列
			Map<String, List<String>> strParamList = Util.getColumnList_4_0(strParams);
			Map<String, Map<String, String>> strColumnList = new LinkedHashMap<String, Map<String, String>>();
			Map<String, String> aryIndexNames = new LinkedHashMap<String, String>();

			String strID = strParamList.get("id").get(0);
			String strIndex = strParamList.get("index").get(0);
			String strDBConnection = strParamList.get("dbConnection").get(0);
			String strSql = "";
			String strCacheSearchSql = "";
			String strResult = "";
			String strRows = "";
			String strGroup = "";
			String strIndexCols = "";

			// 1.查询指标
			strSql = "select zbmc,zdzh from zb where zdid in (" + strIndex.replace("[", "").replace("]", "")
					+ ") and zbsid=" + strID;

			System.out.println("指标SQL:" + strSql);

			rsIndex = oBaseFactory.Query(strSql, requestEntity);

			while (rsIndex.next()) {
				aryIndexNames.put(rsIndex.getString("zdzh"), rsIndex.getString("zbmc"));
				strIndexCols += "'" + rsIndex.getString("zdzh") + "',";
			}

			strIndexCols = strIndexCols.substring(0, strIndexCols.length() - 1);

			// 2.实例化数据库连接
			requestEntity.setDBType(strDBConnection);
			oBaseFactory = new BaseFactory(requestEntity);

			// 3.从缓存表查询数据
			strCacheSearchSql = "select cast(rq as varchar(7)),mc,a0 from sdp_jgj_test.t_zbtx_cache_qs where mc in ("
					+ strIndexCols + ")";

			if (strParamList.get("rq_0") != null) {

				String strRQ_0 = strParamList.get("rq_0").get(0);

				if (strParamList.get("rq_1") != null) {
					String strRQ_1 = strParamList.get("rq_1").get(0);

					strCacheSearchSql += " and rq >= ('" + strRQ_0.substring(0, 7) + "-01'::date)";
					strCacheSearchSql += " and rq <= ('" + strRQ_1.substring(0, 7) + "-01'::date)";
				} else {
					strCacheSearchSql += " and rq = ('" + strRQ_0.substring(0, 7) + "-01'::date)";
				}
			}

			if (strParamList.get("qxcode") != null) {
				String strQXCode = strParamList.get("qxcode").get(0);

				strCacheSearchSql += " and xzqhfrcode0 = " + strQXCode;
			}

			strCacheSearchSql += " order by rq";

			System.out.println("查询缓存表SQL:" + strCacheSearchSql);

			// 6.查询
			rs = oBaseFactory.QueryEx(strCacheSearchSql, requestEntity);

			// 返回结果

			int iGroup = 0;

			// 封装返回对象
			while (rs.next()) {

				String strDate = rs.getString("rq");
				String strIndexName = rs.getString("mc");
				String strValue = rs.getString("a0");

				if (!strColumnList.containsKey(strDate)) {

					Map<String, String> oItem = new LinkedHashMap<String, String>();

					oItem.put(strIndexName, strValue);

					strColumnList.put(strDate, oItem);
				} else {

					strColumnList.get(strDate).put(strIndexName, strValue);
				}

			}

			for (String strDate : strColumnList.keySet()) {

				strRows += "{\"key\":\"" + strDate + "\",\"value\":[";

				for (String strIndexName : aryIndexNames.keySet()) {
					strRows += Common.toPraseInt(strColumnList.get(strDate).get(strIndexName), 0) + ",";
				}

				if (strRows != "") {
					strRows = strRows.substring(0, strRows.length() - 1);
				}

				strRows += "]},";
			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			for (String strName : aryIndexNames.keySet()) {
				strGroup += "\"" + aryIndexNames.get(strName) + "\",";
			}

			if (strGroup != "") {
				strGroup = strGroup.substring(0, strGroup.length() - 1);
			}

			// 封装返回结果
			strResult += "{";
			strResult += "\"code\": \"" + requestEntity.getCode() + "\",";
			strResult += "\"data\": [" + strRows + "],";
			strResult += "\"group\": [" + strGroup + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
				if (rsSjj != null) {
					rsSjj.close();
				}
				if (rsCategory != null) {
					rsCategory.close();
				}
				if (rsSecondCategory != null) {
					rsSecondCategory.close();
				}
				if (rsIndex != null) {
					rsIndex.close();
				}
				if (rsTable != null) {
					rsTable.close();
				}
				if (rsSecondTable != null) {
					rsSecondTable.close();
				}
				if (rsCode != null) {
					rsCode.close();
				}
			} catch (SQLException ex) {
			}
		}

		// System.out.println(requestEntity.getResponse());

		return requestEntity;
	}

	/**
	 * <b> 接口: </b> 临时方法
	 * 
	 * @author xhe
	 * @param requestEntity 接口属性类
	 * @return ApiEntity 接口属性类
	 * @version V1.0.0.0
	 * @version --2021年7月29日
	 * @version --新增方法
	 * @throws SQLException
	 */
	public ApiEntity Search_1_0(ApiEntity requestEntity) {
		CachedRowSet rs = null;

		// 实例化高斯数据库连接
		Map<String, String> oDBConnection = new HashMap<String, String>();

		try {
			oDBConnection = requestEntity.getDBConnection();

			String strParams = "";

			// 解析请求参数
			if (StringUtils.isEmpty(requestEntity.getParams())) {
				requestEntity.setCode(ExecuteEnum.RequestError);
				requestEntity.setMessage("请求参数不能为空!");
			} else {
				strParams = requestEntity.getParams();
			}

			BaseFactory oBaseFactory = new BaseFactory(requestEntity);

			// 解析请求串(json)
			JSONObject jsonObject = JSONObject.fromObject(strParams);

			// 获取参数
			String strSearchCode = jsonObject.getString("SearchCode");
			String strSearchType = jsonObject.getString("SearchType");
			String strDBConnection = jsonObject.getString("DBConnection");
			// 查询总数语句
			String strSearchSql = "select code,name,type,frequency,time,tablename,columns,filter from t_fwpt_search where category="
					+ strSearchType;

			System.out.println(strSearchSql);

			// 查询总数
			rs = oBaseFactory.Query(strSearchSql, requestEntity);

			requestEntity.setDBConnection(strDBConnection);
			oBaseFactory = new BaseFactory(requestEntity);
			int iTotal = 0;
			String strRows = "";

			while (rs.next()) {

				String strCode = rs.getString("code");
				String strName = rs.getString("name");
				String strType = rs.getString("type");
				String strFrequency = rs.getString("frequency");
				String strTime = rs.getString("time");
				String strTable = rs.getString("tablename");
				String strColumns = rs.getString("columns");
				String strFilter = rs.getString("filter");

				// 查询语句
				String strSql = "select " + strColumns + " from " + strTable + " where " + strFilter + "'"
						+ strSearchCode + "'";

				System.out.println(strSql);

				ResultSet rsEx = oBaseFactory.QueryEx(strSql, requestEntity);

				strRows += "{";
				strRows += "\"code\": \"" + strCode + "\",";
				strRows += "\"name\": \"" + strName + "\",";
				strRows += "\"type\": \"" + strType + "\",";
				strRows += "\"frequency\": \"" + strFrequency + "\",";
				strRows += "\"time\": \"" + strTime + "\",";
				strRows += "\"result\": [ ";

				while (rsEx.next()) {
					strRows += "[";

					String[] aryColumns = strColumns.split(",");

					for (String strColumn : aryColumns) {

						strRows += "{\"key\":\"" + strColumn + "\",\"value\":\""
								+ (rsEx.getString(strColumn) == null ? "" : rsEx.getString(strColumn)) + "\"},";
					}

					if (strRows != "") {
						strRows = strRows.substring(0, strRows.length() - 1);
					}

					iTotal += 1;

					strRows += "],";
				}

				if (strRows != "") {
					strRows = strRows.substring(0, strRows.length() - 1);
				}

				strRows += "]";
				strRows += "},";
			}

			if (strRows != "") {
				strRows = strRows.substring(0, strRows.length() - 1);
			}

			// 返回结果
			String strResult = "";

			// 封装返回结果
			strResult += "{";
			strResult += "\"total\": \"" + iTotal + "\",";
			strResult += "\"rows\": [" + strRows + "]";
			strResult += "}";

			requestEntity.setReturnType(false);
			requestEntity.setResult(strResult);

		} catch (Exception ex) {

			requestEntity.setCode(ExecuteEnum.Error);
			requestEntity.setMessage(ex.getMessage());

			System.out.println(ex.getMessage());
		} finally {

			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException ex) {
			}
			requestEntity.setDBConnection(oDBConnection);
		}

		return requestEntity;
	}
}
